<template>
	<view class="page-view">
		<view class="u-flex u-row-between u-m-b-30">
			<view class="evalate-item" :class="[type==1?'u-type-warning':'']" @click="type=1">
				<text class="iconfont icon-haoping"></text>好评
			</view>
			<view class="evalate-item" :class="[type==2?'u-type-warning':'']" @click="type=2">
				<text class="iconfont icon-average"></text>中评
			</view>
			<view class="evalate-item" :class="[type==3?'u-type-warning':'']" @click="type=3">
				<text class="iconfont icon-chaping"></text>差评
			</view>
		</view>
		<view class="u-flex-1" style="height: 0;">
			<u-input type="textarea" placeholder="聊聊本次交易您的感受，您的评价能帮助到其他人" v-model="content" auto-height height="600"
				maxlength="500" :clearable="false"></u-input>
		</view>
		<view class="order-view" @click="$u.route('/pages/subpage/list/serv_detail',{id:order.serve_info.id})"
			v-if="order.serve_info">
			<view class="u-flex-1 u-font-30 font-medium w-0">
				<view class="u-line-1">{{order.serve_info.title || order.demand_info.title}}</view>
			</view>
			<view class="u-type-error">
				￥<text class="u-font-30">{{order.serve_info.price}}</text>
			</view>
		</view>
		<u-button type="primary" hover-class="none" shape="circle" @click="evaluateHandle" :loading="loading">发布</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1,
				content: '',
				order: {},
				role: '',
				loading: false,
				evalType: 1
			}
		},
		onLoad(e) {
			this.role = e.role
			this.evalType = e.type || 1
			if (this.evalType == 2) {
				this.queryDemOrder(e.id)
			} else {
				this.queryDetail(e.id)
			}
			if (e.content) {
				const info = JSON.parse(e.content)
				this.type = info.type;
				this.content = info.content
			}
		},
		methods: {
			evaluateHandle() {
				this.loading = true
				this.$u.api.evaluate(this.order.id, {
					content: this.content,
					type: this.type,
					serve_type: this.evalType
				}).then(res => {
					this.$u.toast('发表成功！')
					setTimeout(() => {
						this.$u.route({
							url: '/pages/subpage/order/comments',
							type: 'redirectTo',
							params: {
								id: this.order.id,
								type: this.evalType,
								role: this.role
							}
						})
					}, 800)
				}).finally(() => {
					this.loading = false
				})
			},
			queryDetail(id) {
				this.$u.api.orderDetail(id).then(res => {
					this.order = res;
				})
			},
			queryDemOrder(id) {
				console.log(this.role);
				if (this.role == 'power') {
					this.$u.api.demOrderInfo(id).then(res => {
						this.order = res;
					})
				} else {
					this.$u.api.demOrderInfoByUser(id).then(res => {
						this.order = res;
					})
				}

			}
		}
	}
</script>

<style scoped lang="scss">
	.page-view {
		height: 100vh;
		display: flex;
		flex-direction: column;
		padding: 20rpx 30rpx 60rpx;
		background-color: #fff;
	}

	.evalate-item {
		width: 190rpx;
		height: 76rpx;
		background: #EEEEEE;
		border-radius: 70rpx 70rpx 70rpx 70rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;

		.iconfont {
			font-size: 48rpx;
			margin-right: 10rpx;
		}
	}

	.order-view {
		display: flex;
		padding: 28rpx;
		border-radius: 20rpx;
		background: #F6F6F6;
		margin-bottom: 20rpx;

		&:before {
			content: "";
			display: inline-block;
			width: 10rpx;
			height: 10rpx;
			border-radius: 50%;
			background-color: #999;
			margin-right: 16rpx;
			margin-top: 16rpx;
		}
	}
</style>